<template>
    <div class="body_background" :style="GetWindowBackground">
        <div class="body_background padding-top10 marBottom">
            <div class="block-box items-start">
                <div class="big-font-size three-color">基础信息</div>
                <ul class="create-box">
                    <li>
                        <div class="big-font-size main-color">计划名称：</div>
                        <input type="text" class="" v-model="plan_name"/>
                    </li>
                    <li>
                        <div class="big-font-size main-color">备注内容：</div>
                        <input type="text" class="" v-model="note"/>
                    </li>
                </ul>
            </div>
            <div class="add-inventory-box green-color middle-font-size"
                 @click="addGoodsFun"
            >
                <span>+</span>
                <span class="padding-left">添加盘点商品</span>
            </div>
            <div class="block-box items-start order-list-box" v-if="goodsList.length>0">
                <div class="big-font-size three-color">盘点商品</div>
                <div class="order-list-item">
                    <div class="order-content-box" v-for="(item,index) in goodsList" :key="item.id">
                        <img :src="item.imgUrl"/>
                        <div class="order-info-box">
                            <div class="main-color big-font-size">{{item.title}}</div>
                            <div class="goods-content">
                                <div>
                                    <div class="three-color small-font-size">分类：蔬菜</div>
                                    <div class="three-color small-font-size">规格：200g</div>
                                    <div class="three-color small-font-size">库存：200袋</div>
                                    <div class="three-color small-font-size">货值：￥2020</div>
                                </div>
                                <div class="price-color big-font-size goods-count"
                                     @click="removeFun(index)"
                                >
                                    移除
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="body_background create-button-box">
            <mt-button class="width40 middle-font-size"
                       @click="cancelClickFun"
            >取消
            </mt-button>
            <mt-button class="width40 middle-font-size background white-color"
                       @click="createInventoryFun"
            >提交
            </mt-button>
        </div>
    </div>
</template>

<script>
    import {Toast} from 'mint-ui';

    export default {
        name: "StockInventoryCreate",
        data() {
            return {
                GetWindowBackground: {
                    'min-height': ''
                },
                goodsList: [],
                note:'',
                plan_name:'',
            }
        },
        mounted() {
            this.getNewGoodsList();//重新整合商品数据
        },
        methods: {
            //重新整合商品数据
            getNewGoodsList() {
                var list = JSON.parse(localStorage.getItem('add_inventory_goods'));
                if (list) {
                    for (var i = 0; i < list.length; i++) {
                        var item = list[i]
                        item.num = 1
                    }
                    this.goodsList = list
                }
                // localStorage.removeItem('add_inventory_goods');
            },

            //移除
            removeFun(index) {
                this.goodsList.splice(index, 1)
                Toast("已移除")
            },

            //取消
            cancelClickFun() {
                localStorage.removeItem('add_inventory_goods');
                this.$router.push('/StockInventoryList')

            },
            //提交
            createInventoryFun() {
                var list = this.goodsList;
                var arr=[];
                for (var i = 0; i < list.length; i++) {
                    var item=list[i]
                    arr.push(item.id)
                }
                var data={
                    name:this.plan_name,
                    note:this.note,
                    arr:JSON.stringify(arr)
                }
                console.log(data)
                return
                this.cancelClickFun()
            },
            //添加商品
            addGoodsFun() {
                this.$router.push('/addGoodsView?type=2')
            },

            getHeight() {
                // 获取浏览器高度
                this.GetWindowBackground['min-height'] = window.innerHeight + 'px'
            },
        },
        // 生命周期 - 创建完成（可以访问当前this实例）
        created() {
            window.addEventListener('resize', this.getHeight) // 注册监听器
            this.getHeight() // 页面创建时先调用一次
        },
        // 生命周期 - 销毁完成
        destroyed() {
            window.removeEventListener('resize', this.getHeight)
        },
    }
</script>

<style lang="scss" scoped>

    .create-box {
        width: 100%;
        padding-bottom: 20px;
        margin-top: 5px;
        li {
            width: 100%;
            height: 45px;
            display: flex;
            align-items: flex-end;
            justify-content: space-between;
            div {
                margin-bottom: 7px;
            }
            input, select {
                width: calc(100% - 100px);
                height: 30px;
                border-top: 0;
                border-left: 0;
                border-right: 0;
                border-bottom: 1px solid #ebedf1;
                outline: none;
                list-style: none;
            }
        }
    }

    .add-inventory-box {
        width: 70%;
        height: 40px;
        line-height: 40px;
        background: #fff;
        border-radius: 6px;
        margin: auto;
        font-size: 14px;
        .padding-left {
            padding-left: 15px;
        }
    }

    .order-list-box {
        margin: 10px auto;
        .order-list-item {
            width: 100%;
            background: #fff;
            margin-top: 10px;
            border-radius: 4px;
            .order-top-box {
                width: 100%;
                height: 35px;
                display: flex;
                justify-content: space-between;
                align-items: center;
            }
            .order-content-box {
                width: 100%;
                display: flex;
                padding: 7px 0;
                img {
                    width: 80px;
                    height: 80px;
                    margin-right: 10px;
                    border-radius: 4px;
                }
                .goods-content {
                    width: 100%;
                    display: flex;
                    justify-content: space-between;
                }
                .order-info-box {
                    width: calc(100% - 70px);
                    display: flex;
                    flex-direction: column;
                    justify-content: space-between;
                    text-align: left;
                }
                .goods-count {
                    margin-left: auto;
                    margin-top: 10px;
                }
            }
        }
    }

    .create-button-box {
        width: 100%;
        height: 70px;
        position: fixed;
        bottom: 0px;
        display: flex;
        justify-content: space-around;
        align-items: center;
        .width40 {
            width: 40%;
            border: 1px solid #05c569;
            color: #05c569;
            border-radius: 10px;
        }
    }

</style>